<?php

namespace app\admin\controller;

use app\common\controller\AdminController;

//引入外部函数
use app\common\model\hfztcy\LibUserVideoAuth;
use common\Common;


/**
 * 视频认证
 * @name VideoAuth.php
 * @package hfztcy
 * @message controller
 * @author rxy
 * @version 1.0
 * @copyright CHANGE INC
 * @since 2020-6-5
 */
class VideoAuth extends AdminController
{
    protected $model;

    /**
     * 构造函数
     */
    public function __construct()
    {
        $this->model = new LibUserVideoAuth();
        $this->rightVerify(session('admin'), url("admin/Login/login"));
        parent::__construct();
    }

    /**
     * 列表页
     */
    function videoAuthList()
    {
        $this->getSetMenu($this);
        $this->log(__CLASS__, __FUNCTION__, "视频认证-列表页", 1, 'view');
        return $this->fetch('VideoAuth/videoAuthList/videoAuthList');
    }

    /**
     * 列表页
     */
    function redMotherVideoAuthList()
    {
        $this->getSetMenu($this);
        $this->log(__CLASS__, __FUNCTION__, "红娘认证-列表页", 1, 'view');
        return $this->fetch('VideoAuth/redMotherVideoAuthList/videoAuthList');
    }

    /**
     * 列表页
     */
    function storeVideoAuthList()
    {
        $this->getSetMenu($this);
        $this->log(__CLASS__, __FUNCTION__, "店铺认证-列表页", 1, 'view');
        return $this->fetch('VideoAuth/storeVideoAuthList/videoAuthList');
    }

    /**
     * 删除
     */
    function deleteVideoAuth()
    {
        $id = input("id");
        $messageRes = $this->model->findUserVideoAuth(['id' => $id]);
        if ($messageRes['errorCode'] == 0) {
            $result = $this->model->deleteUserVideoAuth($id);
            echo json_encode($result);
            die();
        }
        echo json_encode(Common::errorArray(1, '不存在', false));
        die();
    }

    /**
     * 视频认证-分页查询
     */
    function pagingVideoAuth()
    {
        $args = $this->getArgsList($this, ['username','state']);
        $page = $this->getPageInfo();
        $where = [];
        $where[] = "`type` = 1";//视频认证
        if ($args['state'] != '') $where[] = "FIND_IN_SET({$args['state']},identity)";
        if (!empty($args['username'])) $where[] = "`username` like '%" . $args['username'] . "%'";
        $result = $this->model->pagingUserVideoAuth($page, implode(' AND ', $where));
        foreach ($result['data']['dataList'] as &$item) {
            $item['video_url'] = ROOT_URL.'/'.str_replace('upload/','upload/sliceVideo/',$item['video_url']);
        }
        echo json_encode($result);
    }

    /**
     * 红娘-分页查询
     */
    function pagingRedMotherVideoAuth()
    {
        $args = $this->getArgsList($this, ['username','state']);
        $page = $this->getPageInfo();
        $where = [];
        $where[] = "`type` = 2";//红娘认证
        if ($args['state'] != '') $where[] = "FIND_IN_SET({$args['state']},identity)";
        if (!empty($args['username'])) $where[] = "`username` like '%" . $args['username'] . "%'";
        $result = $this->model->pagingUserVideoAuth($page, implode(' AND ', $where));
        foreach ($result['data']['dataList'] as &$item) {
            $item['video_url'] = ROOT_URL.'/'.str_replace('upload/','upload/sliceVideo/',$item['video_url']);
        }
        echo json_encode($result);
    }

    /**
     * 门店-分页查询
     */
    function pagingStoreVideoAuth()
    {
        $args = $this->getArgsList($this, ['username','state']);
        $page = $this->getPageInfo();
        $where = [];
        $where[] = "`type` = 3";//门店认证
        if ($args['state'] != '') $where[] = "FIND_IN_SET({$args['state']},identity)";
        if (!empty($args['username'])) $where[] = "`username` like '%" . $args['username'] . "%'";
        $result = $this->model->pagingUserVideoAuth($page, implode(' AND ', $where));
        foreach ($result['data']['dataList'] as &$item) {
            $item['video_url'] = ROOT_URL.'/'.str_replace('upload/','upload/sliceVideo/',$item['video_url']);
        }
        echo json_encode($result);
    }

    /**
     * Info: 门店状态
     * Date: 2022/6/20 11:24
     */
    public function disabledStatus()
    {
        $id = input("id");
        $status = input("state");

        $result = $this->model->findUserVideoAuth(['id' => $id]);
        if ($result['errorCode'] == 1) {
            echo json_encode(Common::errorArray(1, '不存在', ''));
            die();
        }

        $result = $this->model->updateUserVideoAuth(['id' => $id], ['state' => $status]);
        echo json_encode($result);
        die();
    }
}

?>